package com.chunfeng.mypen.controller;

import com.chunfeng.mypen.entity.Exam;
import com.chunfeng.mypen.result.JsonRequest;
import com.chunfeng.mypen.service.ExamService;
import com.chunfeng.mypen.vo.ExamVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description: 试卷实体类控制层
 * @author: 小雷
 * @createTime: 2023-11-14 00:21:29
 */
@Slf4j
@RestController
@RequestMapping("/exam")
@Api(value = "试卷控制层", tags = "试卷访问操作接口")
public class ExamController {

    @Autowired
    private ExamService examService;

    /**
     * 条件查询所有试卷
     *
     * @param exam 试卷实体类，包含所有查询条件
     * @return
     */
    @GetMapping
    @ApiOperation(value = "分类筛选试卷信息")
    public JsonRequest<List<ExamVo>> lookExam(
            @ApiParam(value = "试卷信息", required = true)
            Exam exam) {
        return examService.lookExam(exam);
    }

    /**
     * 添加试卷信息
     *
     * @param exam 需要添加的实体类
     * @return
     */
    @PostMapping
    @ApiOperation(value = "添加试卷信息")
    public JsonRequest<Integer> addExam(
            @ApiParam(value = "添加的试卷信息", required = true)
            @RequestBody Exam exam) {
        return examService.addExam(exam);
    }

    /**
     * 修改试卷信息
     *
     * @param exam 需要修改的实体类
     * @return
     */
    @PutMapping
    @ApiOperation(value = "修改试卷信息")
    public JsonRequest<Integer> updateExam(
            @ApiParam(value = "修改的试卷信息", required = true)
            @RequestBody Exam exam) {
        return examService.updateExam(exam);
    }

    /**
     * 删除试卷信息
     *
     * @param ids 需要删除的试卷id
     * @return
     */
    @DeleteMapping
    @ApiOperation(value = "删除试卷")
    public JsonRequest<Integer> deleteExam(
            @ApiParam(value = "删除试卷的id", required = true)
            @RequestBody List<String> ids) {
        return examService.deleteExam(ids);
    }
}
